<template>
  <div>
    <el-card class="box-card">
      <el-table :data="tableData"
                style="width: 100%">
        <el-table-column
          prop="index"
          label="订单号"
          width="80">
        </el-table-column>
        <el-table-column
          prop="recipients"
          label="顾客名"
          width="140">
        </el-table-column>
        <el-table-column
          prop="gno"
          label="商品号"
          width="140">
        </el-table-column>
        <el-table-column
          prop="name"
          label="商品名称"
          width="140">
        </el-table-column>
        <el-table-column
          prop="date"
          label="下单日期"
          width="140">
        </el-table-column>
        <el-table-column
          prop="transported"
          label="运费"
          width="140">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址"
          width="140">
        </el-table-column>
        <el-table-column
          prop="telephone"
          label="联系电话"
          width="140">
        </el-table-column>
        <el-table-column
          prop="invoice"
          label="库存量"
          width="140">
        </el-table-column>
        <el-table-column width="250px"
          label="操作">
          <template #default="scope">
            <el-button type="primary" @click="handleEditClick(scope.$index,scope.row)" size="mini">修改</el-button>
            <el-button type="danger" @click="deleteEvent(scope.$index,scope.row)" size="mini">删除</el-button>
            <el-button type="warning" @click="invoiceEvent(scope.$index,scope.row)" size="mini">申请发票</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog title="申请发票" :visible.sync="invoiceBox" width="50%">
        <el-form ref="form" label-width="100px" v-model="user">
          <el-form-item label="发票号:">
            <el-input placeholder="请输入发票号" maxlength="50" v-model = "user.ino"></el-input>
          </el-form-item>
          <el-form-item label="发票类型:">
            <el-input placeholder="请输入发票类型" maxlength="50" v-model = "user.type"></el-input>
          </el-form-item>
          <el-form-item label="抬头类型:">
            <el-input placeholder="请输入抬头类型" maxlength="50" v-model = "user.look"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="handleInvoiceUser">确 认</el-button>
        </span>
      </el-dialog>
      <el-dialog title="修改" :visible.sync="editBox" width="50%">
      <el-form ref="form" label-width="100px" v-model="user">
        <el-form-item label="收件人:">
          <el-input placeholder="请输入收件人姓名" maxlength="50" v-model = "user.recipients"></el-input>
        </el-form-item>
        <el-form-item label="商品名称:">
          <el-input placeholder="请输入商品名称" maxlength="50" v-model = "user.name"></el-input>
        </el-form-item>
        <el-form-item label="下单日期:">
          <el-input placeholder="请输入下单日期" maxlength="50" v-model = "user.date"></el-input>
        </el-form-item>
        <el-form-item label="运费:">
          <el-input placeholder="请输入运费" maxlength="50" v-model = "user.transported"></el-input>
        </el-form-item>
        <el-form-item label="收件地址：">
          <el-input placeholder="请输入地址" maxlength="50" v-model = "user.address"></el-input>
        </el-form-item>
        <el-form-item label="联系电话：">
          <el-input placeholder="请输入联系电话" maxlength="50" v-model = "user.telephone"></el-input>
        </el-form-item>
      </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="handleEditUser">确定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      tableData: [{
        index: '1',
        recipients: '张三',
        gno: '5',
        name: '羽毛球',
        date: '2001-5-5',
        transported: '10',
        address: '北京朝阳区',
        telephone: '1897589625',
        invoice: '20',
        ino: '5',
        type: '增值税',
        look: '个人'
      },
      {
        index: '2',
        recipients: '李四',
        gno: '5',
        name: '毽子',
        date: '2001-5-6',
        transported: '10',
        address: '广州潮汕区',
        telephone: '1846523245',
        invoice: '25',
        ino: '5',
        type: '增值税',
        look: '个人'
      },
      {
        index: '3',
        recipients: '王麻子',
        gno: '6',
        name: '排球',
        date: '2001-5-14',
        transported: '10',
        address: '遵义花岗区',
        telephone: '1158523245',
        invoice: '25',
        ino: '5',
        type: '增值税',
        look: '个人'
      },
      {
        index: '4',
        recipients: '肖四',
        gno: '6',
        name: '运动单车',
        date: '2001-4-14',
        transported: '10',
        address: '河南郑州',
        telephone: '1895425295',
        invoice: '30',
        ino: '5',
        type: '增值税',
        look: '个人'
      },
      {
        index: '3',
        recipients: '老王',
        gno: '6',
        name: '足球',
        date: '2001-6-5',
        transported: '10',
        address: '北京大兴',
        telephone: '14896518765',
        invoice: '25',
        ino: '5',
        type: '增值税',
        look: '个人'
      }
      ],
      editBox: false,
      user: {},
      editIndex: '',
      invoiceBox: false
    }
  },
  methods: {
    deleteEvent (index) {
      this.$confirm('确定要删除吗？', '提示', {
        type: 'warning'
      })
        .then(() => {
          this.$message.success('删除成功')
          this.tableData.splice(index, 1)
        })
        .catch(() => {})
    },
    invoiceEvent () {
      this.invoiceBox = true
    },
    handleInvoiceUser () {
      this.addUserData = {}
      this.$message({ showClose: true, message: '确认成功！', type: 'success' })
    },
    handleEditClick (index, row) {
      this.editBox = true
      this.user = row
      this.editIndex = index
    },
    handleEditUser: function () {
      this.tableData.splice(this.editIndex, 1, this.user)
      this.$message({
        showClose: true,
        message: '修改成功',
        type: 'success'
      })
      this.editBox = false
    }
  }
}
</script>

<style scoped>

</style>
